home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_02 / ED-157 / help_get_kw.c < prev    next >
C/C++ Source or Header  |  1993-09-10  |  2KB  |  88 lines

  1. /*
  2.  * Copyright (C) 1992 by Rush Record (rhr@clio.rice.edu)
  3.  * 
  4.  * This file is part of ED.
  5.  * 
  6.  * ED is free software; you can redistribute it and/or modify it under the terms
  7.  * of the GNU General Public License as published by the Free Software Foundation.
  8.  * 
  9.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  10.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License along with ED
  14.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  15.  * Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17. #include "opsys.h"
  18.  
  19. #include <stdio.h>
  20. #include <string.h>
  21.  
  22. #include "ctyp_dec.h"
  23. #include "library.h"
  24.  
  25. static Char waiting = 0;
  26. static Char keyword[128];    /* keywords may not be more than 127 bytes long */
  27. static Int level;
  28.  
  29. /******************************************************************************\
  30. |Routine: help_get_keyword
  31. |Callby: help_load
  32. |Purpose: Reads the next keyword from the online help file. Returns the tree
  33. |         level of the keyword, or -1 if end of file.
  34. |Arguments:
  35. |    fp is the file pointer for the online help file.
  36. |    keyptr is the returned buffer containing the found keyword.
  37. \******************************************************************************/
  38. Int help_get_keyword(fp,keyptr)
  39. FILE *fp;
  40. Char **keyptr;
  41. {
  42.     Int status;
  43.  
  44.     if(waiting)
  45.         waiting = 0;
  46.     else
  47.     {
  48.         while((status = my_fscanf(fp,"%d%s",&level,keyword)) != 2)
  49.             if(status == EOF)
  50.                 return(-1);
  51.     }
  52.     *keyptr = (Char *)imalloc(strlen(keyword)+1);
  53.     strcpy(*keyptr,keyword);
  54.     return(level);
  55. }
  56.  
  57. /******************************************************************************\
  58. |Routine: help_get_text
  59. |Callby: help_load
  60. |Purpose: Reads and stores online help text. Returns a pointer to the text
  61. |         buffer.
  62. |Arguments:
  63. |    fp is the file pointer of the online help file.
  64. \******************************************************************************/
  65. Char *help_get_text(fp)
  66. FILE *fp;
  67. {
  68.     Char buf[16384],*p,*textptr;
  69.  
  70.     p = buf;
  71.     while(1)
  72.     {
  73.         if(!(fgets(p,sizeof(buf) - (p - buf),fp)))
  74.             break;
  75.         if(my_sscanf(p,"%d%s",&level,keyword) == 2 && !isspace(*p))
  76.         {
  77.             waiting = 1;
  78.             *p = 0;
  79.             break;
  80.         }
  81.         p += strlen(p);
  82.     }
  83.     textptr = (Char *)imalloc(p - buf + 1);
  84.     strcpy(textptr,buf);
  85.     return(textptr);
  86. }
  87.  
  88.